package com.nacos.web.controller;

import com.nacos.test.utils.JSONResult;
import com.nacos.web.feign.PersonFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


/**
 * 项目名称：nacos_parent
 * 类 名 称：WebController
 * 类 描 述：TODO
 * 创建时间：2020/5/14
 * 创 建 人：Areli
 */
@RestController
@RequestMapping("/web")
public class WebController {
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    PersonFeign personFeign;

    @GetMapping
    public JSONResult queryAllUser(){
        return personFeign.queryAll();
    }

    @GetMapping("/{id}")
    public JSONResult getProduct(@PathVariable("id")Integer id){
        //return restTemplate.getForObject("http://nacos-test/person/" + id, JSONResult.class);
        return personFeign.getPersonById(id);
    }

    @GetMapping("ipAndPort")
    public String getIPAndPort(){
        //return restTemplate.getForObject("http://nacos-test/person/getIPAndPort",String.class);
        return personFeign.getIPAndPort();
    }
}
